﻿using System.Diagnostics;
using System;

namespace StockModel
{
	[DebuggerDisplay("Code = {Id.Code}, Name = {Id.Name}")]
    [Serializable]
    public class Stock : IDisposable
	{
		#region Attributes

		public StockId Id { get; private set; }
		public QuotationCalendar QuotationCalendar { get; private set; }

		#endregion

		#region Public Methods

        public Stock(string code, string name)
        {
            this.Id = new StockId();
            this.QuotationCalendar = new QuotationCalendar();
            this.Id.Code = code;
            this.Id.Name = name;
		}

		#endregion

		#region IDisposable

		protected bool Disposed { get; private set; }

		private void Dispose(bool disposing)
		{
			if (!this.Disposed)
			{
				this.InternalDispose(disposing);
			}

			this.Disposed = true;
		}

		protected virtual void InternalDispose(bool disposing)
		{
			if (disposing)
			{
				this.QuotationCalendar.Dispose();
			}

			// Dispose here only unmanaged objects 
			// Don’t use managed objects here because maybe 
			// they have been finalized already
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		~Stock()
		{
			this.Dispose(false);
		}

		#endregion

	}
}
